package fit.conceptmap.service.impl;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import fit.conceptmap.beans.AssignmentBean;
import fit.conceptmap.beans.JsonBean;
import fit.conceptmap.dao.IAssignmentDao;
import fit.conceptmap.dao.IDrawDao;
import fit.conceptmap.entities.Assignment;
import fit.conceptmap.entities.Concept;
import fit.conceptmap.entities.Conceptmap;
import fit.conceptmap.entities.Link;
import fit.conceptmap.entities.Node;
import fit.conceptmap.entities.Relationship;
import fit.conceptmap.services.IAssignmentService;
import fit.conceptmap.utils.DrawUtils;

@Service
public class AssignmentServiceImpl implements IAssignmentService {
	
	@Autowired
	IAssignmentDao assignmentDao;
	@Autowired
	IDrawDao drawDao;
	
	@Override
	public boolean createAssignment(AssignmentBean assignment)
			throws ParseException {
		return assignmentDao.createAssignment(assignment);
	}

	@Override
	public boolean createMemberAssignment(String idMember,
			AssignmentBean assigment) throws ParseException {
		return assignmentDao.createMemberAssignment(idMember, assigment);
	}

	@Override
	public List<JsonBean> getListExercise(String username) {
		List<Conceptmap> lst = assignmentDao.getListExercise(username);
		List<JsonBean> result = new ArrayList<JsonBean>();
		JsonBean json;
		for (Conceptmap conceptmap : lst) {
			json = new JsonBean();
			json.setDescription(conceptmap.getDescription());
			json.setNameConceptMaps(conceptmap.getName());
			json.setIdConceptMaps(conceptmap.getIdConceptMaps());
			json.setDateCreate(conceptmap.getDateCreate().toString());
			result.add(json);
		}
		return result;
	}

	@Override
	public AssignmentBean getInfoAssignmentByConceptMapsId(String username, String conceptmapsID) {
		AssignmentBean result = new AssignmentBean();
		Assignment assignment = assignmentDao.getAssignment(username, conceptmapsID);
		result.setName(assignment.getName());
		result.setOwner(assignment.getUser().getFullName());
		result.setStartTime(assignment.getStartTime().toString());
		result.setDeadline(assignment.getDeadLine().toString());
		return result;
	}

}
